<script>
	// const iac = uni.createInnerAudioContext()
	
export default {
	
	onLaunch: function() {
		this.iac.src = "http://m8.music.126.net/20210601201227/d693243518c323b90d4a11cffcfa3e89/ymusic/560b/060e/5359/aa1ab79b911dbac1cafcd3ecc539dcb6.mp3";
		this.$play();
		this.nowSongDown();
	},
	onShow: function() {
		// this.nextSong()
		console.log('App Show');
	},
	onHide: function() {
		console.log('App Hide');
		
		
	},
	data(){
		return {
			song:{
				id: 1474342935,
				image: 'https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg',
				url: "http://m7.music.126.net/20200925213210/db9365f6e7651b24732f1fd45741f14a/ymusic/obj/w5zDlMODwrDDiGjCn8Ky/3788384004/5b1e/2c7e/670b/5f2b70a177ebeb97730048f367a37e83.mp3",
				author: '黑猫警长Giao',
				title: '画画的baby',
			},
			nextSong:null,
		}
	},
	components:{
	},
	
	computed:{
	},
	methods:{
		// 下一首
		// 播放完成监听
		nowSongDown() {
			this.iac.onEnded(()=>{
				let nowListIndex = this.$store.getters.nextPlayData.nowListIndex;
				let nowSongIndex = this.$store.getters.nextPlayData.nowSongIndex;
				let nowList = this.$store.getters.listData[nowListIndex].lists;
				nowSongIndex = nowSongIndex < nowList.length-1 ? nowSongIndex+1:0;
				uni.request({
					url: "http://119.3.174.206:3000/song/url?id=" + nowList[nowSongIndex].id,
					success: (res) => {
						console.log(res.data)
						if(!res.data.data[0].url)return console.log('这歌要钱')
						this.iac.src = res.data.data[0].url
						this.$store.commit('nowPlayChange', {playState:true});
						this.$store.commit('songChange', {
							...nowList[nowSongIndex],
							url: res.data.data[0].url
						})
						this.iac.play()
						
					}
				})
				console.log('nowList',nowList[nowSongIndex])
				this.$store.commit('nowSongChange', {nowSongIndex: nowSongIndex, nowListIndex: nowListIndex})	
			})
		},
		// 当前播放器时间
		nowSongTime() {
			return {
				currentTime: iac.currentTime,
				allTime: iac.duration,
				buffered: iac.buffered//缓冲位
			}
		},
		// 下一首
		nextSong(that){
			console.log(1);
			console.log(this)
		},
		//播放
		playSong(){
			iac.play();
		},
		// 暂停
		stopSong() {
			iac.pause();
		},
		// 上一首
		lastSong() {
			
		}
	}
};
</script>

<style>
	@import url("http://at.alicdn.com/t/font_2064057_z1hq0qe6n3r.css");
/*每个页面公共css */ 
.uni-tabbar .uni-tabbar__icon.uni-tabbar__icon__diff {
	transition: all linear 1s;
	animation: xuanZhan 3s linear infinite;
}
uni-icon>i:before {
	    margin: 0;
	    box-sizing: border-box;
	    position: absolute;
	    right: 58rpx;
	    top: 30rpx;
		cursor: pointer;
	}
uni-swiper .uni-swiper-slides {
	    margin: 0 22rpx;
	    overflow: hidden;
	    border-radius: 10px;
	}
@keyframes xuanZhan{
	0{}
	100%{
		transform: rotate(360deg);
	}
}
</style>
